<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>Docs For Class Psa_Dully</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
			<div class="page-body">			
<h2 class="class-name"><img src="../media/images/Class_logo.png"
														alt=" Class"
														title=" Class"
														style="vertical-align: middle"> Psa_Dully</h2>

<a name="sec-description"></a>
<div class="info-box">
	<div class="info-box-title">Description</div>
	<div class="nav-bar">
					<span class="disabled">Description</span> |
													<a href="#sec-var-summary">Vars</a> (<a href="#sec-vars">details</a>)
						|											<a href="#sec-method-summary">Methods</a> (<a href="#sec-methods">details</a>)
						
					</div>
	<div class="info-box-body">
        		<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Simple template engine class.</p>
<p class="description"><p>I called this class Dully to be opposite to <a href="http://www.smarty.net">Smarty</a>.  I needed some simple name and something like '<em>simple_template</em>' seemed too long.  It has few methods that are similar to those in Smarty template engine.</p><p>All that Dully does is to put values from associative array into local namespace and  includes .php (template) file. There are no special template tags, just use PHP code  blocks to echo values. Templates are ordinary PHP files and you can write them  as any other .php script, but keep in mind that the point of template engine  should be to separate business logic from presentation.  So you should not put any logic (calculations, getting data from a database ...)  into templates. With <a href="http://www.smarty.net">Smarty</a> that is easier to achieve  and it has many advanced features so I suggest that you use Smarty as template engine.  But if you know what you are doing or need simple and fast template  engine or don't want to learn Smarty's tags you can use Dully.  Dully class doesn't include anything from PSA so you can use it as template engine in any PHP application.</p><p>This class is inspired from <a href="http://www.massassi.com/php/articles/template_engines/">http://www.massassi.com/php/articles/template_engines/</a> and there are  some interesting thoughts about template engines.</p><p><strong>Examples</strong></p><p><strong>1)</strong> Simple example with one template file:</p><p>Template file <samp>template.tpl</samp>:  <div class="src-code"><ol><li><div class="src-line">This&nbsp;is&nbsp;text&nbsp;from&nbsp;template&nbsp;file&nbsp;template.php</div></li>
<li><div class="src-line">&lt;br/&gt;</div></li>
<li><div class="src-line">My&nbsp;car&nbsp;is&nbsp;<span class="src-php">&lt;?php&nbsp;</span>echo&nbsp;<span class="src-var">$my_car_color&nbsp;</span><span class="src-php">?&gt;</span>.&lt;br/&gt;</div></li>
<li><div class="src-line">Something&nbsp;else:&nbsp;&lt;?=&nbsp;$some_name&nbsp;?&gt;</div></li>
</ol></div></p><p>.php file:  <div class="src-code"><ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;include&nbsp;Psa_Dully&nbsp;class</span></div></li>
<li><div class="src-line"><span class="src-inc">include&nbsp;</span><span class="src-str">'../scripts/Psa_Dully.class.php'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;make&nbsp;new&nbsp;Psa_Dully&nbsp;object</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../psa/Psa_Dully.html">Psa_Dully</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;Set&nbsp;path&nbsp;to&nbsp;folder&nbsp;with&nbsp;templates&nbsp;without&nbsp;'/'&nbsp;at&nbsp;the&nbsp;end.</span></div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;You&nbsp;can&nbsp;also&nbsp;do&nbsp;this&nbsp;my&nbsp;passing&nbsp;value&nbsp;as&nbsp;an&nbsp;argument&nbsp;to&nbsp;constructor&nbsp;</span></div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;and&nbsp;skip&nbsp;this&nbsp;line&nbsp;(see&nbsp;second&nbsp;example).</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../psa/Psa_Dully.html#var$template_dir">template_dir</a>&nbsp;&nbsp;</span>=&nbsp;<span class="src-str">'templates'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;assign&nbsp;some&nbsp;data&nbsp;for&nbsp;template</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Dully.html#methodassign">assign</a><span class="src-sym">(</span><span class="src-str">'my_car_color'</span><span class="src-sym">,</span><span class="src-str">'Black'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Dully.html#methodassign">assign</a><span class="src-sym">(</span><span class="src-str">'some_name'</span><span class="src-sym">,</span><span class="src-str">'bla&nbsp;bla&nbsp;bla'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;display&nbsp;fetched&nbsp;template</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Dully.html#methoddisplay">display</a><span class="src-sym">(</span><span class="src-str">'template.tpl'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-php">?&gt;</span></div></li>
</ol></div></p><p>The printout of the above .php script will be:  <pre> This is text from template file template.php
 My car is Black.
 Something else: bla bla bla</pre></p><p><strong>Note:</strong> you can write <kbd>&lt;?= $some_name ?&gt;</kbd> instead of <kbd>&lt;?php echo $some_name ?&gt;</kbd>.  Use of this shortcut requires <var>short_open_tag</var> PHP ini option to be on (default is on).</p><p><strong>2)</strong> You can put one rendered template into another:</p><p>template file <samp>template1.tpl</samp>:  <div class="src-code"><ol><li><div class="src-line">This&nbsp;is&nbsp;text&nbsp;from&nbsp;template1.php&lt;br/&gt;</div></li>
<li><div class="src-line">&lt;?=&nbsp;$var1&nbsp;?&gt;&lt;br/&gt;</div></li>
<li><div class="src-line">&lt;?=&nbsp;$var2&nbsp;?&gt;</div></li>
</ol></div></p><p>template file <samp>template2.tpl</samp>:  <div class="src-code"><ol><li><div class="src-line">This&nbsp;is&nbsp;text&nbsp;from&nbsp;template2.php</div></li>
</ol></div></p><p>.php file:  <div class="src-code"><ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;include&nbsp;Psa_Dully&nbsp;class</span></div></li>
<li><div class="src-line"><span class="src-inc">include&nbsp;</span><span class="src-str">'../scripts/Psa_Dully.class.php'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;make&nbsp;new&nbsp;Psa_Dully&nbsp;object&nbsp;and&nbsp;set&nbsp;folder&nbsp;with&nbsp;templates</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../psa/Psa_Dully.html">Psa_Dully</a></span><span class="src-sym">(</span><span class="src-str">'templates'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;put&nbsp;content&nbsp;of&nbsp;fetched&nbsp;template&nbsp;template2.tpl&nbsp;in&nbsp;$var1</span></div></li>
<li><div class="src-line"><span class="src-var">$var1&nbsp;</span>=&nbsp;<span class="src-var">$Psa_Dully</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Dully.html#methodfetch">fetch</a><span class="src-sym">(</span><span class="src-str">'template2.tpl'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;assign&nbsp;values&nbsp;var1&nbsp;and&nbsp;var2</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Dully.html#methodassign">assign</a><span class="src-sym">(</span><span class="src-str">'var1'</span><span class="src-sym">,</span><span class="src-var">$var1</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Dully.html#methodassign">assign</a><span class="src-sym">(</span><span class="src-str">'var2'</span><span class="src-sym">,</span><span class="src-str">'bla&nbsp;bla&nbsp;bla'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;display&nbsp;fetched&nbsp;template&nbsp;template1.tpl</span></div></li>
<li><div class="src-line"><span class="src-var">$Psa_Dully</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Dully.html#methoddisplay">display</a><span class="src-sym">(</span><span class="src-str">'template1.tpl'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-php">?&gt;</span></div></li>
</ol></div></p><p>The above example will output:  <pre> This is text from template1.php
 This is text from template2.php
 bla bla bla</pre></p><p><strong>3)</strong> In this kind of templates it's nice to use alternative PHP syntax for control structures.  See details in PHP <a href="http://www.php.net/manual/en/control-structures.alternative-syntax.php">manual</a>.  <div class="src-code"><ol><li><div class="src-line">&nbsp;&lt;?&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-var">$variable&nbsp;</span>=&nbsp;<span class="src-str">'abcd'</span><span class="src-sym">)</span>:&nbsp;<span class="src-php">?&gt;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;this&nbsp;is&nbsp;something&lt;/h1&gt;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bla&nbsp;bla</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/p&gt;</div></li>
<li><div class="src-line">&nbsp;&lt;?&nbsp;endif&nbsp;?&gt;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&lt;?&nbsp;foreach&nbsp;($array&nbsp;as&nbsp;$value):&nbsp;?&gt;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&gt;&lt;?=&nbsp;$value['email'])&nbsp;?&gt;&lt;/div&gt;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&gt;&lt;?=&nbsp;$value['phone_number'])&nbsp;?&gt;&lt;/div&gt;</div></li>
<li><div class="src-line">&nbsp;&lt;?&nbsp;endforeach&nbsp;?&gt;</div></li>
</ol></div></p></p>
		<p class="notes">
			Located in <a class="field" href="_scripts---Psa_Dully.class.php.html">/scripts/Psa_Dully.class.php</a> (line <span class="field"><a href="../__filesource/fsource_psa__scriptsPsa_Dully.class.php.html#a103">103</a></span>)
		</p>
		
				
		<pre></pre>
	
			</div>
</div>



	<a name="sec-var-summary"></a>
	<div class="info-box">
		<div class="info-box-title">Variable Summary</span></div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
						<span class="disabled">Vars</span> (<a href="#sec-vars">details</a>)
							| 
									<a href="#sec-method-summary">Methods</a> (<a href="#sec-methods">details</a>)
							
								</div>
		<div class="info-box-body">
			<div class="var-summary">
																								<div class="var-title">
					<img src="../media/images/Variable.png" alt=" " />
					<span class="var-type">string</span>
					<a href="#$template_dir" title="details" class="var-name">$template_dir</a>
				</div>
											</div>
		</div>
	</div>

	<a name="sec-method-summary"></a>
	<div class="info-box">
		<div class="info-box-title">Method Summary</span></div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
																		<a href="#sec-var-summary">Vars</a> (<a href="#sec-vars">details</a>)
				 
				|
						<span class="disabled">Methods</span> (<a href="#sec-methods">details</a>)
		</div>
		<div class="info-box-body">			
			<div class="method-summary">
																																																<div class="method-definition">
					<img src="../media/images/Constructor.png" alt=" "/>
											<span class="method-result">Psa_Dully</span>
										<a href="#__construct" title="details" class="method-name">__construct</a>
											([<span class="var-type">string</span>&nbsp;<span class="var-name">$template_dir</span> = <span class="var-default">null</span>])
									</div>
																<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">void</span>
										<a href="#assign" title="details" class="method-name">assign</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$name</span>, <span class="var-type">mixed</span>&nbsp;<span class="var-name">$value</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">void</span>
										<a href="#display" title="details" class="method-name">display</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$template_file</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">string</span>
										<a href="#fetch" title="details" class="method-name">fetch</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$template_filE</span>)
									</div>
											</div>
		</div>
	</div>		

	<a name="sec-vars"></a>
	<div class="info-box">
		<div class="info-box-title">Variables</div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
										<a href="#sec-var-summary">Vars</a> (<span class="disabled">details</span>)
						
			
										| 
									<a href="#sec-method-summary">Methods</a> (<a href="#sec-methods">details</a>)
							
					</div>
		<div class="info-box-body">
			
<a name="var$template_dir" id="$template_dir"><!-- --></A>
<div class="evenrow">

	<div class="var-header">
		<img src="../media/images/Variable.png" />
		<span class="var-title">
			<span class="var-type">string</span>
			<span class="var-name">$template_dir</span>
						(line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Dully.class.php.html#a120">120</a></span>)
		</span>
	</div>

	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Folder with templates.</p>
<p class="description"><p>Without '/' at the end.</p></p>
	<ul class="tags">
				<li><span class="field">access:</span> public</li>
			</ul>
	
	
		
		

</div>
						
		</div>
	</div>
	
	<a name="sec-methods"></a>
	<div class="info-box">
		<div class="info-box-title">Methods</div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
															<a href="#sec-var-summary">Vars</a> (<a href="#sec-vars">details</a>)
														<a href="#sec-method-summary">Methods</a> (<span class="disabled">details</span>)
						
		</div>
		<div class="info-box-body">
			<A NAME='method_detail'></A>
<a name="method__construct" id="__construct"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<img src="../media/images/Constructor.png" />
		<span class="method-title">Constructor __construct</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Dully.class.php.html#a128">128</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Sets $template_dir member value if passed as argument</p>
	
	<div class="method-signature">
		<span class="method-result">Psa_Dully</span>
		<span class="method-name">
			__construct
		</span>
					([<span class="var-type">string</span>&nbsp;<span class="var-name">$template_dir</span> = <span class="var-default">null</span>])
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$template_dir</span><span class="var-description">: the directory with templates</span>			</li>
				</ul>
		
			
	</div>
<a name="methodassign" id="assign"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">assign</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Dully.class.php.html#a144">144</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Assigns values to the templates.</p>
<p class="description"><p>See examples in <a href="../psa/Psa_Dully.html">Psa_Dully</a> class description.</p></p>
	<ul class="tags">
				<li><span class="field">see:</span> <a href="../psa/plugins/Psa_Plugin_Controller.html#methoddully_assign_result">Psa_Plugin_Controller::dully_assign_result()</a></li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Dully.html#methodfetch">Psa_Dully::fetch()</a></li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Dully.html#methoddisplay">Psa_Dully::display()</a></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">void</span>
		<span class="method-name">
			assign
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$name</span>, <span class="var-type">mixed</span>&nbsp;<span class="var-name">$value</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$name</span><span class="var-description">: variable name in template</span>			</li>
					<li>
				<span class="var-type">mixed</span>
				<span class="var-name">$value</span><span class="var-description">: variable value in template</span>			</li>
				</ul>
		
			
	</div>
<a name="methoddisplay" id="display"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">display</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Dully.class.php.html#a180">180</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Outputs the fetched template.</p>
<p class="description"><p>See examples in <a href="../psa/Psa_Dully.html">Psa_Dully</a> class description.</p></p>
	<ul class="tags">
				<li><span class="field">see:</span> <a href="../psa/Psa_Dully.html#methodfetch">Psa_Dully::fetch()</a></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">void</span>
		<span class="method-name">
			display
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$template_file</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$template_file</span><span class="var-description">: template file name (path)</span>			</li>
				</ul>
		
			
	</div>
<a name="methodfetch" id="fetch"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">fetch</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Dully.class.php.html#a157">157</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Returns the fetched template as string.</p>
<p class="description"><p>See examples in <a href="../psa/Psa_Dully.html">Psa_Dully</a> class description.</p></p>
	<ul class="tags">
				<li><span class="field">return:</span> fetched (rendered) template</li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Dully.html#methoddisplay">Psa_Dully::display()</a></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			fetch
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$template_filE</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$template_filE</span><span class="var-description">: template file name (path)</span>			</li>
				</ul>
		
			
	</div>
						
		</div>
	</div>

	
	<p class="notes" id="credit">
		Documentation generated on Thu, 21 Oct 2010 01:40:49 +0200 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.3</a>
	</p>
	</div></body>
</html>